package com.neusoft.yiyang.diet.controller;

import com.neusoft.yiyang.common.entity.diet.FoodTag;
import com.neusoft.yiyang.diet.service.FoodTagService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "食材标签关联接口", description = "管理食材与饮食标签的关联关系")
@RestController
@RequestMapping("/food-tags")
public class FoodTagController {

    @Autowired
    private FoodTagService foodTagService;

    @Operation(summary = "添加食材-标签关联", description = "为指定食材绑定饮食标签（建立多对多关联）")
    @PostMapping("/add")
    public void addFoodTag(
            @Parameter(description = "食材-标签关联信息（含食材ID和标签ID）", required = true)
            @RequestBody FoodTag foodTag) {
        foodTagService.addFoodTag(foodTag);
    }

    @Operation(summary = "获取所有食材-标签关联", description = "查询系统中所有食材与标签的关联记录")
    @GetMapping("/all")
    public List<FoodTag> getAllFoodTags() {
        return foodTagService.getAllFoodTags();
    }

    @Operation(summary = "查询食材关联的标签", description = "获取指定食材绑定的所有饮食标签")
    @GetMapping("/food/{foodId}")
    public List<FoodTag> getFoodTagsByFoodId(
            @Parameter(description = "食材ID", required = true)
            @PathVariable Integer foodId) {
        return foodTagService.getFoodTagsByFoodId(foodId);
    }

    @Operation(summary = "查询标签关联的食材", description = "获取指定饮食标签绑定的所有食材")
    @GetMapping("/tag/{tagId}")
    public List<FoodTag> getFoodTagsByTagId(
            @Parameter(description = "饮食标签ID", required = true)
            @PathVariable Integer tagId) {
        return foodTagService.getFoodTagsByTagId(tagId);
    }

    @Operation(summary = "删除食材-标签关联", description = "解除指定食材与标签的绑定关系")
    @DeleteMapping("/delete/{foodId}/{tagId}")
    public void deleteFoodTag(
            @Parameter(description = "食材ID", required = true)
            @PathVariable Integer foodId,
            @Parameter(description = "饮食标签ID", required = true)
            @PathVariable Integer tagId) {
        foodTagService.deleteFoodTag(foodId, tagId);
    }
}